#include <iostream>

using namespace std;

class Shape {
public:
    virtual void ShowArea() const {};
};

class Rectangle : public Shape {
public:
    // 无参构造器
    Rectangle();

    // 构造函数
    Rectangle(int newLength, int newWidth);

    // 调整矩形长宽
    void setRectangle(int newLength, int newWidth);

    void ShowArea() const {
        cout << "The area of rectangle is:" << area << endl;
    }

private:
    double length, width, area;
};

class Triangle : public Shape {
public:
    // 无参构造器
    Triangle();

    // 构造函数
    Triangle(int newButton, int newHeight);

    void setTriangle(int newButton, int newHeight);

    void ShowArea() const {
        cout << "The area of triangle is:" << area << endl;
    }

private:
    double button, height, area;
};

Rectangle::Rectangle() {
    setRectangle(0, 0);
}

Rectangle::Rectangle(int newLength, int newWidth) {
    Rectangle::setRectangle(newLength, newWidth);
}

void Rectangle::setRectangle(int newLength, int newWidth) {
    length = newLength > 0 ? newLength : 0;
    width = newWidth > 0 ? newWidth : 0;
    Rectangle::area = length * width;
}

Triangle::Triangle() {
    setTriangle(0, 0);
}

Triangle::Triangle(int newButton, int newHeight) {
    Triangle::setTriangle(newButton, newHeight);
}

void Triangle::setTriangle(int newButton, int newHeight) {
    button = newButton > 0 ? newButton : 0;
    height = newHeight > 0 ? newHeight : 0;
    Triangle::area = 0.5 * button * height;
}

int main() {
    // 构造函数创建对象
    Rectangle rectangle(5, 10);
    // 对象调用ShowArea()
    rectangle.ShowArea();
    // 创建基类指针
    Shape *r1 = new Rectangle(rectangle);
    // 基类指针调用ShowArea()
    r1->ShowArea();
    // 构造函数创建对象
    Triangle triangle(3, 5);
    // 对象调用ShowArea()
    triangle.ShowArea();
    // 创建基类指针
    Shape *t1 = new Triangle(triangle);
    // 基类指针调用ShowArea()
    t1->ShowArea();
    return 0;
}